package com.ak.server.platform.service.impl;

import com.ak.common.entity.QueryRequest;
import com.ak.common.entity.constant.AKConstant;
import com.ak.common.entity.system.Datasource;
import com.ak.common.entity.system.DatasourceApplication;
import com.ak.common.exception.AKException;
import com.ak.common.utils.SortUtil;
import com.ak.server.platform.mapper.DatasourceApplicationMapper;
import com.ak.server.platform.mapper.DatasourceMapper;
import com.ak.server.platform.service.IDatasourceApplicationService;
import com.ak.server.platform.service.IDatasourceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;


/**
 * 数据源业务实现
 *
 * @author Vean
 */
@Service
public class DatasourceApplicationServiceImpl extends ServiceImpl<DatasourceApplicationMapper, DatasourceApplication> implements IDatasourceApplicationService {

    @Override
    public boolean authApplication(String datasourceCode, String appCodes) {
        try {
            this.baseMapper.deleteByDatasourceCodeOrAppCode(datasourceCode, null);
            this.baseMapper.batchDatasourceApplication(datasourceCode, Arrays.asList(appCodes.split(",")));
            return true;
        } catch (AKException e) {
            throw new AKException("为租户分配子系统异常");
        }
    }
}
